package org.zfes.snowier.common.monitor.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
import java.util.Properties;


public class ConfigReader {

	public static Optional<String> getConfig(String filePath,String key) {
		String cofigVal="";
		Properties properties = new Properties();
	    //InputStream in = ConfigReader.class.getClassLoader().getResourceAsStream("config/config.properties");
		InputStream in = ConfigReader.class.getClassLoader().getResourceAsStream(filePath);
	    try {
			properties.load(in);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException("配置文件读取错误");
		}
	    cofigVal= properties.getProperty( key);
	    if(cofigVal==null||"".equals(cofigVal.trim())) {
	    	return Optional.empty();
	    }
	    return  Optional.of(cofigVal);
	}
	
}
